

public class Factory {
    public static fruit getInstance(String name) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        fruit fruit = null;
        try {
            fruit = (fruit) Class.forName(name).newInstance();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return fruit;
    }

    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        fruit orange = Factory.getInstance("orange");
        orange.eat();
    }
}
